//
//  Team9SubjectViewController.m
//  Team9Project
//
//  Created by dllo on 15/10/19.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9SubjectViewController.h"
#import "Team9SubjectDetailTableViewCell.h"
#import "JQAFNetworkTool.h"
#import "Team9SubjectDetailModel.h"
#import <UIImageView+WebCache.h>
#import "Team9DesignVC.h"

#define WID 375.0

@interface Team9SubjectViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *subTableView;
@property (nonatomic, strong) NSMutableArray *subArr;

@end

@implementation Team9SubjectViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

#pragma mark 首页灵感图集push页面
    
    self.view.backgroundColor = [UIColor cyanColor];
    self.title = self.str;
    
    self.subTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEGHT - 64 - 49) style:UITableViewStylePlain];
    self.subTableView.dataSource = self;
    self.subTableView.delegate = self;
    [self.view addSubview:self.subTableView];
    self.subTableView.rowHeight = 130 / WID * WIDTH;
    self.subTableView.showsVerticalScrollIndicator = NO;
    
    [self createData];
}

#pragma mark 数据解析
- (void)createData{
    NSString *str = [NSString stringWithFormat:@"http://api.meilijia.com/app/featured_subject?subject_id=%ld", self.ID];
     
    [JQAFNetworkTool getUrl:str body:nil result:JQJSON headerFile:nil success:^(id result) {
        
        NSMutableDictionary *dic = result[@"data"][@"featured_subject"][@"info"];
        self.subArr = [NSMutableArray array];
        self.subArr = [Team9SubjectDetailModel baseModelByArr:dic[@"collections"]].mutableCopy;
        [self.subTableView reloadData];
    } failure:^(NSError *error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.subArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *subReuse = @"subReuse";
    Team9SubjectDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:subReuse];
    if (!cell) {
        cell = [[Team9SubjectDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:subReuse];
    }
    Team9SubjectDetailModel *model = self.subArr[indexPath.row];
    [Team9Tool sd_imageView:cell.author_faceImageView image:model.author_face placeholderImage:@"333"];
    cell.author_nickLabel.text = model.author_nick;
    [Team9Tool sd_imageView:cell.albumImageView image:model.cover_pic placeholderImage:@"111"];
    [Team9Tool sd_imageView:cell.upImageView image:model.items[0][@"pic"] placeholderImage:@"111"];
    [Team9Tool sd_imageView:cell.downImageView image:model.items[1][@"pic"] placeholderImage:@"111"];
    cell.titleLabel.text = model.title;
    cell.liked_countImageView.image = [UIImage imageNamed:@"like"];
    NSString *comment_countStr = [NSString stringWithFormat:@"%ld", model.liked_count];
    cell.liked_countLabel.text = comment_countStr;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Team9SubjectDetailModel *model = self.subArr[indexPath.row];
    Team9DesignVC *designVC = [Team9DesignVC new];
    designVC.url = [NSString stringWithFormat:@"http://api.meilijia.com/app/collection_page2?col_id=%ld&tab=photo", model.id];
#pragma mark 隐藏tabBar
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:designVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;

}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
